Learning Spring 5.0 by Tejaswini Mandar Jog

Learning Spring 5.0 by Tejaswini Mandar Jog

Author:Tejaswini Mandar Jog [Jog, Tejaswini Mandar]
Language: eng
Format: azw3
Tags: COM051000 - COMPUTERS / Programming / General, COM051280 - COMPUTERS / Programming Languages / Java, COM051390 - COMPUTERS / Programming / Open Source
Publisher: Packt Publishing
Published: 2017-06-29T04:00:00+00:00


@Override public Book serachBook(longISBN) { // TODO Auto-generated method stub String SEARCH_BOOK = "select * from book where ISBN=?"; Book book_serached = null; try { book_serached =

jdbcTemplate.queryForObject(SEARCH_BOOK, new Object[] { ISBN }, new RowMapper<Book>(){ @Override public Book mapRow(ResultSet set, int rowNum) throws SQLException { Book book = new Book(); book.setBookName(set.getString("bookName")); book.setAuthor(set.getString("author")); book.setDescription(set.getString("description")); book.setISBN(set.getLong("ISBN")); book.setPrice(set.getInt("price")); book.setPublication(set.getString("publication")); return book; } }); return book_serached; } catch (EmptyResultDataAccessException ex) { return new Book(); } }

We have added an anonymous inner class, which is implementing RowMapper. RowMapper is used to bind column values that are fetched from the database table to the object of Book returned by the queryForObject() method. The code is searching for the book, and then the column values from ResultSet are bounded to the Book object. We returned an object with default values just for our business logic.

Add the BookService interface as a service layer in the com.packt.ch05.service package with the following method signatures:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.